uarti2cspi2 2.2.0
Loading...
Searching...
No Matches
uarti2cspi2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef UARTI2CSPI2_H
29#define UARTI2CSPI2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
60
65
70
75#define UARTI2CSPI2_REG_RHR 0x00
76#define UARTI2CSPI2_REG_THR 0x00
77#define UARTI2CSPI2_REG_IRQEN 0x01
78#define UARTI2CSPI2_REG_IRQSTS 0x02
79#define UARTI2CSPI2_REG_LSR_IRQEN 0x03
80#define UARTI2CSPI2_REG_LSR_IRQSTS 0x04
81#define UARTI2CSPI2_REG_SPCHR_IRQEN 0x05
82#define UARTI2CSPI2_REG_SPCHR_IRQSTS 0x06
83#define UARTI2CSPI2_REG_STS_IRQEN 0x07
84#define UARTI2CSPI2_REG_STS_IRQSTS 0x08
85#define UARTI2CSPI2_REG_MODE1 0x09
86#define UARTI2CSPI2_REG_MODE2 0x0A
87#define UARTI2CSPI2_REG_LCR 0x0B
88#define UARTI2CSPI2_REG_RXTO 0x0C
89#define UARTI2CSPI2_REG_HDPIXDELAY 0x0D
90#define UARTI2CSPI2_REG_IRDA 0x0E
91#define UARTI2CSPI2_REG_FLOWLVL 0x0F
92#define UARTI2CSPI2_REG_FIFOTRIGLVL 0x10
93#define UARTI2CSPI2_REG_TXFIFOLVL 0x11
94#define UARTI2CSPI2_REG_RXFIFOLVL 0x12
95#define UARTI2CSPI2_REG_FLOWCTRL 0x13
96#define UARTI2CSPI2_REG_XON1 0x14
97#define UARTI2CSPI2_REG_XON2 0x15
98#define UARTI2CSPI2_REG_XOFF1 0x16
99#define UARTI2CSPI2_REG_XOFF2 0x17
100#define UARTI2CSPI2_REG_GPIOCFG 0x18
101#define UARTI2CSPI2_REG_GPIODATA 0x19
102#define UARTI2CSPI2_REG_PLLCFG 0x1A
103#define UARTI2CSPI2_REG_BRGCFG 0x1B
104#define UARTI2CSPI2_REG_BRGDIVLSB 0x1C
105#define UARTI2CSPI2_REG_BRGDIVMSB 0x1D
106#define UARTI2CSPI2_REG_CLKSRC 0x1E
107#define UARTI2CSPI2_REG_GLOBAL_IRQ 0x1F
108#define UARTI2CSPI2_REG_GLOBAL_CMD 0x1F
109#define UARTI2CSPI2_REG_TXSYNCH 0x20
110#define UARTI2CSPI2_REG_SYNCHDELAY1 0x21
111#define UARTI2CSPI2_REG_SYNCHDELAY2 0x22
112#define UARTI2CSPI2_REG_TIMER1 0x23
113#define UARTI2CSPI2_REG_TIMER2 0x24
114#define UARTI2CSPI2_REG_REVID 0x25
115 // uarti2cspi2_reg
117
122
127
132#define UARTI2CSPI2_IRQ_CTS 0x80
133#define UARTI2CSPI2_IRQ_RX_EMPTY 0x40
134#define UARTI2CSPI2_IRQ_TX_FIFO_EMPTY 0x20
135#define UARTI2CSPI2_IRQ_TX_TRG 0x10
136#define UARTI2CSPI2_IRQ_RX_TRG 0x08
137#define UARTI2CSPI2_IRQ_STS 0x04
138#define UARTI2CSPI2_IRQ_SP_CHR 0x02
139#define UARTI2CSPI2_IRQ_LSR_ERR 0x01
140
145#define UARTI2CSPI2_LSR_IRQ_CTS 0x80
146#define UARTI2CSPI2_LSR_IRQ_NOISE_INT 0x20
147#define UARTI2CSPI2_LSR_IRQ_R_BREAK 0x10
148#define UARTI2CSPI2_LSR_IRQ_FRAME_ERR 0x08
149#define UARTI2CSPI2_LSR_IRQ_PARITY 0x04
150#define UARTI2CSPI2_LSR_IRQ_R_OVERR 0x02
151#define UARTI2CSPI2_LSR_IRQ_R_TIMEOUT 0x01
152
157#define UARTI2CSPI2_SPCHR_IRQ_MULTI_DROP 0x20
158#define UARTI2CSPI2_SPCHR_IRQ_BREAK 0x10
159#define UARTI2CSPI2_SPCHR_IRQ_XOFF2 0x08
160#define UARTI2CSPI2_SPCHR_IRQ_XOFF1 0x04
161#define UARTI2CSPI2_SPCHR_IRQ_XON2 0x02
162#define UARTI2CSPI2_SPCHR_IRQ_XON1 0x01
163
168#define UARTI2CSPI2_STS_IRQ_TX_EMPTY 0x80
169#define UARTI2CSPI2_STS_IRQ_SLEEP 0x40
170#define UARTI2CSPI2_STS_IRQ_CLK_READY 0x20
171#define UARTI2CSPI2_STS_IRQ_GPI3 0x08
172#define UARTI2CSPI2_STS_IRQ_GPI2 0x04
173#define UARTI2CSPI2_STS_IRQ_GPI1 0x02
174#define UARTI2CSPI2_STS_IRQ_GPI0 0x01
175
180#define UARTI2CSPI2_MODE1_AUTO_SLEEP 0x40
181#define UARTI2CSPI2_MODE1_FORCED_SLEEP 0x20
182#define UARTI2CSPI2_MODE1_TRNSCV_CTRL 0x10
183#define UARTI2CSPI2_MODE1_RTS_HIZ 0x08
184#define UARTI2CSPI2_MODE1_TX_HIZ 0x04
185#define UARTI2CSPI2_MODE1_TX_DISABLE 0x02
186#define UARTI2CSPI2_MODE1_RX_DISABLE 0x01
187
192#define UARTI2CSPI2_MODE2_ECHO_SUPRS 0x80
193#define UARTI2CSPI2_MODE2_MULTI_DROP 0x40
194#define UARTI2CSPI2_MODE2_LOOPBACK 0x20
195#define UARTI2CSPI2_MODE2_SPECIAL_CHR 0x10
196#define UARTI2CSPI2_MODE2_R_FIFO_EMPTY_INV 0x08
197#define UARTI2CSPI2_MODE2_RX_TRIG_INV 0x04
198#define UARTI2CSPI2_MODE2_FIFO_RST 0x02
199#define UARTI2CSPI2_MODE2_RST 0x01
200
205#define UARTI2CSPI2_LCR_RTS_BIT 0x80
206#define UARTI2CSPI2_LCR_TX_BREAK 0x40
207#define UARTI2CSPI2_LCR_FORCE_PARITY 0x20
208#define UARTI2CSPI2_LCR_EVEN_PARITY 0x10
209#define UARTI2CSPI2_LCR_PARITY_EN 0x08
210#define UARTI2CSPI2_LCR_STOP_BITS_1 0x00
211#define UARTI2CSPI2_LCR_STOP_BITS_2_OR_1_5 0x04
212#define UARTI2CSPI2_LCR_STOP_BITS_MASK 0x04
213#define UARTI2CSPI2_LCR_WORD_LENGTH_5 0x00
214#define UARTI2CSPI2_LCR_WORD_LENGTH_6 0x01
215#define UARTI2CSPI2_LCR_WORD_LENGTH_7 0x02
216#define UARTI2CSPI2_LCR_WORD_LENGTH_8 0x03
217#define UARTI2CSPI2_LCR_WORD_LENGTH_MASK 0x03
218
223#define UARTI2CSPI2_IRDA_TX_INV 0x20
224#define UARTI2CSPI2_IRDA_RX_INV 0x10
225#define UARTI2CSPI2_IRDA_MIR 0x08
226#define UARTI2CSPI2_IRDA_SIR 0x02
227#define UARTI2CSPI2_IRDA_IRDA_EN 0x01
228
233#define UARTI2CSPI2_FLOWCTRL_SW_FLOW_NO_FLOW 0x00
234#define UARTI2CSPI2_FLOWCTRL_SW_FLOW_MASK 0xF0
235
240#define UARTI2CSPI2_BRGCFG_4XMODE 0x20
241#define UARTI2CSPI2_BRGCFG_2XMODE 0x10
242#define UARTI2CSPI2_BRGCFG_FRACT_MASK 0x0F
243
248#define UARTI2CSPI2_CLKSRC_CLK_TO_RTS 0x80
249#define UARTI2CSPI2_CLKSRC_PLL_BYPASS 0x08
250#define UARTI2CSPI2_CLKSRC_PLL_EN 0x04
251#define UARTI2CSPI2_CLKSRC_CRYSTAL_EN 0x02
252
257#define UARTI2CSPI2_GLOBAL_IRQ_IRQ1 0x02
258#define UARTI2CSPI2_GLOBAL_IRQ_IRQ0 0x01
259
264#define UARTI2CSPI2_GLOBAL_CMD_TX0 0xE0
265#define UARTI2CSPI2_GLOBAL_CMD_TX1 0xE1
266#define UARTI2CSPI2_GLOBAL_CMD_TX2 0xE2
267#define UARTI2CSPI2_GLOBAL_CMD_TX3 0xE3
268#define UARTI2CSPI2_GLOBAL_CMD_TX4 0xE4
269#define UARTI2CSPI2_GLOBAL_CMD_TX5 0xE5
270#define UARTI2CSPI2_GLOBAL_CMD_TX6 0xE6
271#define UARTI2CSPI2_GLOBAL_CMD_TX7 0xE7
272#define UARTI2CSPI2_GLOBAL_CMD_TX8 0xE8
273#define UARTI2CSPI2_GLOBAL_CMD_TX9 0xE9
274#define UARTI2CSPI2_GLOBAL_CMD_TX10 0xEA
275#define UARTI2CSPI2_GLOBAL_CMD_TX11 0xEB
276#define UARTI2CSPI2_GLOBAL_CMD_TX12 0xEC
277#define UARTI2CSPI2_GLOBAL_CMD_TX13 0xED
278#define UARTI2CSPI2_GLOBAL_CMD_TX14 0xEE
279#define UARTI2CSPI2_GLOBAL_CMD_TX15 0xEF
280#define UARTI2CSPI2_GLOBAL_CMD_EN_EXT_REGMAP 0xCE
281#define UARTI2CSPI2_GLOBAL_CMD_DIS_EXT_REGMAP 0xCD
282
287#define UARTI2CSPI2_TXSYNCH_CLK_TO_GPIO 0x80
288#define UARTI2CSPI2_TXSYNCH_TX_AUTO_DIS 0x40
289#define UARTI2CSPI2_TXSYNCH_TRIG_DELAY 0x20
290#define UARTI2CSPI2_TXSYNCH_SYNCH_EN 0x10
291#define UARTI2CSPI2_TXSYNCH_TRIG_SEL3 0x08
292#define UARTI2CSPI2_TXSYNCH_TRIG_SEL2 0x04
293#define UARTI2CSPI2_TXSYNCH_TRIG_SEL1 0x02
294#define UARTI2CSPI2_TXSYNCH_TRIG_SEL0 0x01
295
300#define UARTI2CSPI2_REVID_MAJOR 0xC0
301#define UARTI2CSPI2_REVID_MAJOR_MASK 0xF0
302#define UARTI2CSPI2_REVID_MINOR_MASK 0x0F
303
308#define UARTI2CSPI2_BAUDRATE_1200 1200ul
309#define UARTI2CSPI2_BAUDRATE_2400 2400ul
310#define UARTI2CSPI2_BAUDRATE_4800 4800ul
311#define UARTI2CSPI2_BAUDRATE_9600 9600ul
312#define UARTI2CSPI2_BAUDRATE_14400 14400ul
313#define UARTI2CSPI2_BAUDRATE_19200 19200ul
314#define UARTI2CSPI2_BAUDRATE_38400 38400ul
315#define UARTI2CSPI2_BAUDRATE_57600 57600ul
316#define UARTI2CSPI2_BAUDRATE_115200 115200ul
317#define UARTI2CSPI2_BAUDRATE_230400 230400ul
318#define UARTI2CSPI2_BAUDRATE_460800 460800ul
319#define UARTI2CSPI2_CRYSTAL_FREQ 1843200ul
320
325#define UARTI2CSPI2_UART_SEL_0 0
326#define UARTI2CSPI2_UART_SEL_1 1
327#define UARTI2CSPI2_SPI_UART_SEL_0 0x00
328#define UARTI2CSPI2_SPI_UART_SEL_1 0x20
329#define UARTI2CSPI2_SPI_UART_SEL_MASK 0x20
330#define UARTI2CSPI2_SPI_REG_MASK 0x1F
331#define UARTI2CSPI2_SPI_WRITE_BIT 0x80
332#define UARTI2CSPI2_I2C_UART_SEL_0 0x20
333#define UARTI2CSPI2_I2C_UART_SEL_1 0x10
334#define UARTI2CSPI2_I2C_UART_SEL_MASK 0x30
335#define UARTI2CSPI2_FIFO_LEN 128
336
342#define UARTI2CSPI2_DEVICE_ADDRESS_A1A0_00 0x6C
343#define UARTI2CSPI2_DEVICE_ADDRESS_A1A0_01 0x61
344#define UARTI2CSPI2_DEVICE_ADDRESS_A1A0_10 0x64
345#define UARTI2CSPI2_DEVICE_ADDRESS_A1A0_11 0x65
346
355#define UARTI2CSPI2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
356#define UARTI2CSPI2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
357 // uarti2cspi2_set
359
364
369
374#define UARTI2CSPI2_MAP_MIKROBUS( cfg, mikrobus ) \
375 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
376 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
377 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
378 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
379 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
380 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
381 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
382 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
383 // uarti2cspi2_map // uarti2cspi2
386
397
402struct uarti2cspi2_s;
403typedef err_t ( *uarti2cspi2_master_io_t )( struct uarti2cspi2_s*, uint8_t, uint8_t*, uint8_t );
404
409typedef struct uarti2cspi2_s
410{
411 digital_out_t rst;
412
413 digital_in_t int_pin;
414
415 i2c_master_t i2c;
416 spi_master_t spi;
417
419 pin_name_t chip_select;
421
424
425 uint8_t act_uart;
426
428
433typedef struct
434{
435 pin_name_t scl;
436 pin_name_t sda;
437 pin_name_t miso;
438 pin_name_t mosi;
439 pin_name_t sck;
440 pin_name_t cs;
441 pin_name_t rst;
442 pin_name_t int_pin;
443
444 uint32_t i2c_speed;
445 uint8_t i2c_address;
446
447 uint32_t spi_speed;
448 spi_master_mode_t spi_mode;
449 spi_master_chip_select_polarity_t cs_polarity;
450
452
454
465
471
482
498
513
527
542err_t uarti2cspi2_write_regs ( uarti2cspi2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
543
558err_t uarti2cspi2_read_regs ( uarti2cspi2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
559
572err_t uarti2cspi2_write_reg ( uarti2cspi2_t *ctx, uint8_t reg, uint8_t data_in );
573
586err_t uarti2cspi2_read_reg ( uarti2cspi2_t *ctx, uint8_t reg, uint8_t *data_out );
587
600
610
620
630
640
650
663err_t uarti2cspi2_set_baud_rate ( uarti2cspi2_t *ctx, uint32_t baud_rate, uint32_t *act_baud_rate );
664
677err_t uarti2cspi2_write_data ( uarti2cspi2_t *ctx, uint8_t *data_in, uint8_t len );
678
691err_t uarti2cspi2_read_data ( uarti2cspi2_t *ctx, uint8_t *data_out, uint8_t len );
692
693#ifdef __cplusplus
694}
695#endif
696#endif // UARTI2CSPI2_H
697 // uarti2cspi2
699
700// ------------------------------------------------------------------------ END
void uarti2cspi2_drv_interface_sel(uarti2cspi2_cfg_t *cfg, uarti2cspi2_drv_t drv_sel)
UART I2C SPI 2 driver interface setup function.
err_t uarti2cspi2_read_regs(uarti2cspi2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
UART I2C SPI 2 read registers function.
err_t uarti2cspi2_read_reg(uarti2cspi2_t *ctx, uint8_t reg, uint8_t *data_out)
UART I2C SPI 2 read register function.
void uarti2cspi2_disable_device(uarti2cspi2_t *ctx)
UART I2C SPI 2 disable device function.
void uarti2cspi2_enable_device(uarti2cspi2_t *ctx)
UART I2C SPI 2 enable device function.
err_t uarti2cspi2_set_baud_rate(uarti2cspi2_t *ctx, uint32_t baud_rate, uint32_t *act_baud_rate)
UART I2C SPI 2 set baud rate function.
void uarti2cspi2_select_uart_1(uarti2cspi2_t *ctx)
UART I2C SPI 2 select UART 1 function.
err_t uarti2cspi2_write_data(uarti2cspi2_t *ctx, uint8_t *data_in, uint8_t len)
UART I2C SPI 2 write data function.
err_t uarti2cspi2_init(uarti2cspi2_t *ctx, uarti2cspi2_cfg_t *cfg)
UART I2C SPI 2 initialization function.
err_t uarti2cspi2_default_cfg(uarti2cspi2_t *ctx)
UART I2C SPI 2 default configuration function.
uint8_t uarti2cspi2_get_int_pin(uarti2cspi2_t *ctx)
UART I2C SPI 2 get INT pin function.
err_t uarti2cspi2_check_com(uarti2cspi2_t *ctx)
UART I2C SPI 2 communication check function.
err_t uarti2cspi2_write_reg(uarti2cspi2_t *ctx, uint8_t reg, uint8_t data_in)
UART I2C SPI 2 write register function.
err_t uarti2cspi2_write_regs(uarti2cspi2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
UART I2C SPI 2 write registers function.
void uarti2cspi2_select_uart_0(uarti2cspi2_t *ctx)
UART I2C SPI 2 select UART 0 function.
void uarti2cspi2_cfg_setup(uarti2cspi2_cfg_t *cfg)
UART I2C SPI 2 configuration object setup function.
err_t uarti2cspi2_read_data(uarti2cspi2_t *ctx, uint8_t *data_out, uint8_t len)
UART I2C SPI 2 read data function.
This file contains SPI specific macros, functions, etc.
UART I2C SPI 2 Click configuration object.
Definition uarti2cspi2.h:434
uint32_t i2c_speed
Definition uarti2cspi2.h:444
spi_master_chip_select_polarity_t cs_polarity
Definition uarti2cspi2.h:449
pin_name_t sck
Definition uarti2cspi2.h:439
spi_master_mode_t spi_mode
Definition uarti2cspi2.h:448
pin_name_t mosi
Definition uarti2cspi2.h:438
uint32_t spi_speed
Definition uarti2cspi2.h:447
pin_name_t scl
Definition uarti2cspi2.h:435
uarti2cspi2_drv_t drv_sel
Definition uarti2cspi2.h:451
pin_name_t int_pin
Definition uarti2cspi2.h:442
pin_name_t miso
Definition uarti2cspi2.h:437
pin_name_t sda
Definition uarti2cspi2.h:436
pin_name_t rst
Definition uarti2cspi2.h:441
pin_name_t cs
Definition uarti2cspi2.h:440
uint8_t i2c_address
Definition uarti2cspi2.h:445
UART I2C SPI 2 Click context object.
Definition uarti2cspi2.h:410
spi_master_t spi
Definition uarti2cspi2.h:416
uint8_t act_uart
Definition uarti2cspi2.h:425
digital_in_t int_pin
Definition uarti2cspi2.h:413
uarti2cspi2_master_io_t read_f
Definition uarti2cspi2.h:423
i2c_master_t i2c
Definition uarti2cspi2.h:415
digital_out_t rst
Definition uarti2cspi2.h:411
uarti2cspi2_drv_t drv_sel
Definition uarti2cspi2.h:420
uint8_t slave_address
Definition uarti2cspi2.h:418
pin_name_t chip_select
Definition uarti2cspi2.h:419
uarti2cspi2_master_io_t write_f
Definition uarti2cspi2.h:422
struct uarti2cspi2_s uarti2cspi2_t
UART I2C SPI 2 Click context object.
err_t(* uarti2cspi2_master_io_t)(struct uarti2cspi2_s *, uint8_t, uint8_t *, uint8_t)
Definition uarti2cspi2.h:403
uarti2cspi2_return_value_t
UART I2C SPI 2 Click return value data.
Definition uarti2cspi2.h:460
@ UARTI2CSPI2_OK
Definition uarti2cspi2.h:461
@ UARTI2CSPI2_ERROR
Definition uarti2cspi2.h:462
uarti2cspi2_drv_t
UART I2C SPI 2 Click driver selector.
Definition uarti2cspi2.h:392
@ UARTI2CSPI2_DRV_SEL_I2C
Definition uarti2cspi2.h:394
@ UARTI2CSPI2_DRV_SEL_SPI
Definition uarti2cspi2.h:393